<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/11/1
 * Time: 16:54
 */

if (!defined('IN_DISCUZ')) {
    exit('Access Denied');
}

if(empty($_POST)){
    die('<script>alert("内容为空,请重新选择要删除的数据!");history.go(-1)</script>');
}

foreach($_POST['delete'] as $k=>$v){
    //根据删除的id查询  channelId
    $data[] = C::t('#zhibo#zhibo')->getByIdChannelId($v);
}


$url = 'http://test.olbike.com:81/php/bikeshop/V2/?service=Live.Delete';

//使用id 删除 本地数据库的视频
foreach($data as $k2=>$v2){
    //根据删除的id查询  channelId

    //删除本地
    $delData = C::t('#zhibo#zhibo')->delByIdChannelId($v2);

    //删除远程API
    $data = [
        'channelIds'=>$v2 //参数数组
    ];
    $ch = curl_init();  //开启curl
    curl_setopt($ch, CURLOPT_URL, $url);  //curl请求地址
    curl_setopt($ch, CURLOPT_POST, 1);   //请求一个正规的HTTP POST请求, 第三个参数要非零
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);   //默认0是直接将信息显示在浏览器中,设为1表示就能取值
    curl_setopt($ch, CURLOPT_HEADER,0);  //如果成功,请求头信息不显示, 1就显示
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);  //使用POST方法请求
    $buf = curl_exec($ch);    //抓取URL并把它传递给浏览器
}

if($buf['data']['code'] == 0){
    echo '<script>alert("删除成功");history.go(-1);location.reload()</script>';
}






//使用channelId 删除 Api的视频


//print_r($_POST);